package com.zx.sa.controller;

import com.zx.sa.common.ModelType;
import com.zx.sa.controller.valid.ValidMessage;
import com.zx.sa.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin(origins = "*")
public class ChatController {

    @Autowired
    private ChatService chatService;

    @GetMapping("/")
    public String index(Model model) {
        model.addAttribute("models", ModelType.getModels());
        return "index";
    }

    /**
     * 文本
     */
    @ValidMessage
    @RequestMapping("/chat")
    @ResponseBody
    public String chat(@RequestParam(value = "msg", defaultValue = "") String msg,
            @RequestParam(value = "modelType", defaultValue = ModelType.DEFAULT) String modelType) {
        return chatService.chat(msg, modelType);
    }

} 